<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\controller;


use app\common\model\OtcFeedback;
use app\common\model\OtcOrder;
use app\common\model\UserPayType;
use think\Db;

/**
 * 管理员控制器
 */
class Otc extends AdminBase
{


    



    /**
     *
     */
    public function otc_attestation()
    {

        $this->assign('list', $this->logicOtc->otc_attestation($this->param,'a.*,c.username','a.create_time desc'));
        $this->assign('param',$this->param);
        return $this->fetch();
    }

    /**
     *
     */
    public function otc_attestation_check()
    {
        IS_POST && $this->jump($this->logicOtc->otc_attestation_check($this->param));
        $this->assign('param',$this->param);
        $info = $this->logicOtc->getOtcInfo(['id' => $this->param['id']]);
        $this->assign('info', $info);
        return $this->fetch();
    }


    /**
     *OTC买单
     */
    public function trade_list()
    {
        $this->param['type']=1;
        $this->assign('list', $this->logicOtc->getTradeList($this->param,'a.*,c.username,c.is_company,mobile,s.shop_name,c.area','state asc, feed_count desc ,match_count asc ,price asc ,a.id desc'));
        $this->assign('wallet', \app\common\model\Wallet::all(['is_currency'=>1,'status'=>1,'is_virtual'=>1]));
        $this->assign('param',$this->param);
        return $this->fetch();
    }
    /**
     * 添加买卖单
     */
    public function TradeAdd()
    {

        IS_POST && $this->jump($this->logicOtc->trade_add($this->param));
        $this->assign('type',$this->param['type']);
        $this->assign('wallet', \app\common\model\Wallet::all(['is_currency'=>1,'status'=>1,'is_virtual'=>1]));
        return $this->fetch('trade_edit');
    }

    /**
     * 添加定单
     */
    public function OrderAdd()
    {

        IS_POST && $this->jump($this->logicOtc->otc_order_edit($this->param));
        return $this->fetch('order_edit');
    }


    /**
     *OTC卖单列表
     */
    public function trade_sell_list()
    {
        $this->param['type']=2;
        if(!empty($this->param['order'])){
            if($this->param['order']==2){
                $order='state asc,feed_count asc ,match_count asc ,price asc ,a.id asc';
            }else{
                $order='state asc,feed_count desc ,match_count asc ,price asc ,a.id asc';
            }
        }else{
            $order='state asc,feed_count desc ,match_count asc ,price asc ,a.id asc';
        }
        $this->assign('list', $this->logicOtc->getTradeList($this->param,'a.*,c.username,c.is_company,c.mobile,s.shop_name,c.area',$order));
        $this->assign('wallet', \app\common\model\Wallet::all(['is_currency'=>1,'status'=>1,'is_virtual'=>1]));
        $this->assign('param',$this->param);
        return $this->fetch('trade_list');
    }
    /**
     *OTC求购出售订单详情
     */
    public function trade_detail()
    {

        $this->assign('info', $this->logicOtc->trade_detail($this->param));

        return $this->fetch();
    }

    /**
     * OTC买卖单记录导出
     */
    public function exportOtcTradeList()
    {



        $this->logicOtc->exportOtcTradeList($this->param);
    }

    /**
     *审核OTC
     */
    public function trade_check()
    {
        $this->jump($this->logicOtc->trade_check($this->param));

    }

    /**
     *OTC订单列表
     */
    public function trade_order_list()
    {
        if(!empty($this->param['otcorder'])){
            $info= OtcOrder::get($this->param['id']);
            $this->assign('info',$info);
            $this->assign('param',$this->param);
            return $this->fetch('trade_order_pay');
        }
        $this->assign('list', $this->logicOtc->getOrderList($this->param,'a.*,c.username,c.is_company,s.shop_name,c.area','a.create_time desc'));
        $this->assign('wallet', \app\common\model\Wallet::all(['is_currency'=>1,'status'=>1,'is_virtual'=>1]));
        $this->assign('param',$this->param);
        return $this->fetch();
    }

    /**
     *OTC订单详情
     */
    public function trade_order_detail()
    {

        !empty($this->param['update'])  &&  $this->jump($this->logicOtc->orderEdit($this->param));
        $info= OtcOrder::get($this->param['id']);
        $info['buy_pay_list']=UserPayType::all(['user_id'=>$info['user_id'],'status'=>1]);

        $info['sell_pay_list']=UserPayType::all(['user_id'=>$info['uid'],'status'=>1]);


        $this->assign('info',$info);

        return $this->fetch();
    }

    /**
     *OTC订单详情
     */
    public function trade_order_feedback()
    {

        IS_POST  &&  $this->jump($this->logicOtc->order_check($this->param));
        $info= OtcFeedback::get($this->param['feedback_id']);

        $this->assign('info',$info);

        return $this->fetch();
    }

    /**
     * OTC订单记录导出
     */
    public function exportOtcOrderList()
    {



        $this->logicOtc->exportOtcOrderList($this->param);
    }


    /**
     *OTC申诉订单列表
     */
    public function trade_order_appeal_list()
    {
        $this->assign('list', $this->logicOtc->getOrderFeedBackList($this->param,'a.*,c.username','a.create_time desc'));
        $this->assign('wallet', \app\common\model\Wallet::all(['is_currency'=>1,'status'=>1,'is_virtual'=>1]));
        $this->assign('param',$this->param);
        return $this->fetch();
    }

    /**
     *审核OTC
     */
    public function order_check()
    {
        $this->jump($this->logicOtc->order_check($this->param));

    }







}
